package cn.tedu.yxcar.product.service.impl;

import cn.tedu.yxcar.product.ex.CoolSharkServiceException;
import cn.tedu.yxcar.product.mapper.ReservationMapper;
import cn.tedu.yxcar.product.pojo.dto.ReservationAddDTO;
import cn.tedu.yxcar.product.pojo.entity.Reservation;
import cn.tedu.yxcar.product.pojo.entity.order.Order;
import cn.tedu.yxcar.product.pojo.vo.ArticleDetailsVO;
import cn.tedu.yxcar.product.pojo.vo.CarShowVO;
import cn.tedu.yxcar.product.service.IReservationServiceImpl;
import cn.tedu.yxcar.product.web.ResponseCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class ReservationServiceImpl implements IReservationServiceImpl {

    @Autowired
    private ReservationMapper reservationMapper;

    @Override
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    public void addNew(ReservationAddDTO reservationAddDTO) {
        log.debug("开始处理【添加订单】的业务，参数：{}", reservationAddDTO);
        // 创建Order对象
        Reservation reservation = new Reservation();
        // 调用BeanUtils.copyProperties(源,目标)将参数对象中的属性复制到Album对象中
        BeanUtils.copyProperties(reservationAddDTO, reservation);
        // 调用Mapper对象的insert()执行插入数据
        log.debug("即将执行插入数据，参数：{}", reservation);
        int rows = reservationMapper.insertReservation(reservation);
        if (rows != 1) {
            String message = "添加预约失败，服务器忙，请稍后再次尝试！";
            log.warn(message);
            throw new CoolSharkServiceException(ResponseCode.NOT_FOUND, message);
        }


    }

}
